﻿using Autofac;
using Sodao.Demo.Core.Configuration;
using Sodao.Demo.Domain;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace Sodao.Demo.Application
{
    public static class AutoFacExtensions
    {
        /// <summary>
        /// DI 容器注入应用层
        /// </summary>
        /// <param name="autoFacManage"></param>
        public static void AddApplicationDI(this AutoFacManage autoFacManage)
        {
            autoFacManage.AddDomainDI();//DI注入领域层
            autoFacManage.Register(builder => {
                Assembly assembliesRepository = Assembly.Load("Sodao.Demo.Application");


                builder.RegisterAssemblyTypes(assembliesRepository).Where(t => t.Name.EndsWith("Service")).AsImplementedInterfaces().SingleInstance();

            });
        }
    }
}
